﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

namespace Babylon.Toolbox
{
    static partial class EffectCacheSystem
    {
        static readonly Dictionary<GraphicsDevice, ShadersCacheSystem> shadersCache = new Dictionary<GraphicsDevice, ShadersCacheSystem>();

        internal static VertexShader GetVertexShaderCache(GraphicsDevice device)
        {
            if (!shadersCache.ContainsKey(device))
                return null;

            return shadersCache[device].VertexShaderCache;
        }

        internal static PixelShader GetPixelShaderCache(GraphicsDevice device)
        {
            if (!shadersCache.ContainsKey(device))
                return null;

            return shadersCache[device].PixelShaderCache;
        }

        internal static void SetVertexShaderCache(GraphicsDevice device, VertexShader shader)
        {
            if (!shadersCache.ContainsKey(device))
                shadersCache.Add(device, new ShadersCacheSystem());

            shadersCache[device].VertexShaderCache = shader;
        }

        internal static void SetPixelShaderCache(GraphicsDevice device, PixelShader shader)
        {
            if (!shadersCache.ContainsKey(device))
                shadersCache.Add(device, new ShadersCacheSystem());

            shadersCache[device].PixelShaderCache = shader;
        }

        internal static VertexShader CompileVertexShader(GraphicsDevice device, Uri shaderUri)
        {
            if (!shadersCache.ContainsKey(device))
                shadersCache.Add(device, new ShadersCacheSystem());

            return shadersCache[device].CompileVertexShader(device, shaderUri);
        }

        internal static PixelShader CompilePixelShader(GraphicsDevice device, Uri shaderUri)
        {
            if (!shadersCache.ContainsKey(device))
                shadersCache.Add(device, new ShadersCacheSystem());

            return shadersCache[device].CompilePixelShader(device, shaderUri);
        }
    }
}
